$(function () {
    init();
    function init() {
        getQueryTopCategory();
        eventList();
    }
    function eventList() {
        $('.lt-view-left').on('tap', 'li', function () {
            console.log(2);
            
            //点击li时获取对应的id
            var id = $(this).data('id');
            getQuerySecondCategory(id)
            $(this).addClass('active').siblings().removeClass('active');
        })
    }
    function getQueryTopCategory() {
        $.get(location.origin + '/category/queryTopCategory', function (ret) {
            // console.log(ret);
            var html = template('leftTemp', { arr: ret.rows });
            $('.lt-view-left').html(html);
            var id = ret.rows[0].id;
            getQuerySecondCategory(id);
        })
    }

    function getQuerySecondCategory(id) {
        var url = location.origin + '/category/querySecondCategory?id=' + id;
        $.get(url, function (ret) {
            console.log(ret);
            
          if(ret.rows.length>0){
              var html = template('rightTemp',{arr:ret.rows});
              console.log(html);
              $('.lt-view-right').html(html);
          }else{
              $('.lt-view-right').html('没有更多数据...');
          }
        })
    }
})